<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Schleifen &mdash; PowerShell fuer Systemintegratoren</title>
    
    <link rel="stylesheet" href="../_static/sphinxdoc.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '1.0',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/translations.js"></script>
    <link rel="top" title="PowerShell fuer Systemintegratoren" href="../index.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="Allgemeiner Index"
             accesskey="I">Index</a></li>
        <li><a href="../index.html">PS4SYS</a> &raquo;</li> 
      </ul>
    </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../index.html">
              <img class="logo" src="../_static/PowerShell_icon_small.png" alt="Logo"/>
            </a></p>
  <h3>Diese Seite</h3>
  <ul class="this-page-menu">
    <li><a href="../_sources/loesung_rst/Loesung_PowerShell_Schleifen.txt"
           rel="nofollow">Quelltext anzeigen</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Schnellsuche</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Los" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Geben Sie Suchbegriffe oder einen Modul-, Klassen- oder Funktionsnamen ein.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="schleifen">
<h1>Schleifen<a class="headerlink" href="#schleifen" title="Permalink zu dieser Überschrift">¶</a></h1>
<ul id="loesung-schleifen">
<li><p class="first"><strong>Ping</strong></p>
<blockquote>
<div><p>Schreiben Sie eine Programm, welches Ihnen alle per PING erreichbaren Rechner eines Netzes ermittelt. Das Programm soll alle Adressen von 192.168.0.1 bis 192.168.0.255 pingen. Wenn ein PINg erfolgreich war, soll dies als Ausgabe angezeigt werden.</p>
<div class="highlight-sh"><div class="highlight"><pre><span class="nv">$ping</span> <span class="o">=</span> New-Object System.Net.NetworkInformation.Ping
<span class="nv">$i</span> <span class="o">=</span> 0
<span class="nv">$liste</span> <span class="o">=</span> 1..255
<span class="k">for</span><span class="o">(</span><span class="nv">$y</span><span class="o">=</span>0;<span class="nv">$y</span> -le 255;<span class="nv">$y</span>++<span class="o">)</span>
<span class="o">{</span>
        <span class="nv">$ip</span> <span class="o">=</span> <span class="s2">&quot;192.168.0.&quot;</span> + <span class="o">[</span>string<span class="o">]</span><span class="nv">$liste</span><span class="o">[</span><span class="nv">$y</span><span class="o">]</span>
        <span class="nv">$Res</span> <span class="o">=</span> <span class="nv">$ping</span>.send<span class="o">(</span><span class="nv">$ip</span><span class="o">)</span>
        <span class="k">if</span> <span class="o">(</span><span class="nv">$Res</span>.Status -eq <span class="s2">&quot;Success&quot;</span><span class="o">)</span>
        <span class="o">{</span>
                        <span class="nv">$result</span> <span class="o">=</span> <span class="nv">$ip</span> + <span class="s2">&quot; = Success&quot;</span>
                        Write-Host <span class="nv">$result</span>
                        <span class="nv">$y</span>++
        <span class="o">}</span>
<span class="o">}</span>
<span class="nv">$Hosts</span> <span class="o">=</span> <span class="o">[</span>string<span class="o">]</span><span class="nv">$y</span> + <span class="s2">&quot; Hosts is pingable&quot;</span>
Write-Host <span class="nv">$Hosts</span>

<span class="c">#Eine andere Lösung ist powershell-typischer (per pipeline)</span>

<span class="nv">$ping</span> <span class="o">=</span> New-Object System.Net.NetworkInformation.Ping
<span class="nv">$i</span> <span class="o">=</span> 0
1..255 | foreach
<span class="o">{</span>
        <span class="nv">$ip</span> <span class="o">=</span> <span class="s2">&quot;192.168.0.$_&quot;</span>
        <span class="nv">$Res</span> <span class="o">=</span> <span class="nv">$ping</span>.send<span class="o">(</span><span class="nv">$ip</span><span class="o">)</span>

        <span class="k">if</span> <span class="o">(</span><span class="nv">$Res</span>.Status -eq <span class="s2">&quot;Success&quot;</span><span class="o">)</span>
        <span class="o">{</span>
                <span class="nv">$result</span> <span class="o">=</span> <span class="nv">$ip</span> + <span class="s2">&quot; = Success&quot;</span>
                Write-Host <span class="nv">$result</span>
                <span class="nv">$i</span>++
        <span class="o">}</span>
 <span class="o">}</span>
 <span class="nv">$Hosts</span> <span class="o">=</span> <span class="o">[</span>string<span class="o">]</span><span class="nv">$i</span> + <span class="s2">&quot; Hosts is pingable&quot;</span>
 Write-Host <span class="nv">$Hosts</span>
</pre></div>
</div>
</div></blockquote>
</li>
<li><p class="first"><strong>ZahlenRaten</strong></p>
<p>Erstellen sie ein Skript, welches folgende Aufgabe erfüllt: Es muss eine Meldung anzeigen, in der der Benutzer aufgefordert wird, eine Zahl zwischen 1 und 50 einzugebeenn. Das Skript muss die vom Benutzer eingegebene Zahl mit einer zufällig generierten Zahl vergleichen. Wenn die Zahlen nicht übereinstimmen, muss das Skript eine Meldung anzeigen, in der angegeben wird, ob die geratene Zahl zu hoch oder zu niedrig war, und der Benutzer aufgefordert wird, noch einmal zu raten.</p>
<p>Wenn der Benutzer richtig rät, muss das Skript die Zufallszahl sowie die Anzahl der Rateversuche anzeigen. An diesem Punkt ist das Spiel beendet, das Skript muss also auch beendet werden.</p>
<div class="highlight-sh"><div class="highlight"><pre><span class="nv">$guesses</span> <span class="o">=</span> 0

<span class="nv">$low</span> <span class="o">=</span> 1
<span class="nv">$high</span> <span class="o">=</span> 50

<span class="nv">$a</span> <span class="o">=</span> New-Object Random
<span class="nv">$a</span> <span class="o">=</span> <span class="nv">$a</span>.Next<span class="o">(</span><span class="nv">$low</span>,<span class="nv">$high</span><span class="o">)</span>

<span class="k">while</span> <span class="o">(</span><span class="nv">$true</span><span class="o">)</span>
<span class="o">{</span>
        <span class="nv">$guess</span> <span class="o">=</span> <span class="nb">read</span>-host <span class="s2">&quot;Enter a number between 1 and 50: &quot;</span>
        <span class="nv">$guesses</span>++

        <span class="k">if</span> <span class="o">(</span><span class="nv">$guess</span> -eq <span class="nv">$a</span><span class="o">)</span>
        <span class="o">{</span>
                        <span class="s2">&quot;Random Number: &quot;</span> + <span class="nv">$guess</span>
                        <span class="s2">&quot;Number of Guesses: &quot;</span> + <span class="nv">$guesses</span>
                        <span class="nb">break</span>
        <span class="o">}</span>
        elseif <span class="o">(</span><span class="nv">$guess</span> -gt <span class="nv">$a</span><span class="o">)</span>
        <span class="o">{</span>
                        <span class="s2">&quot;Too high&quot;</span>
        <span class="o">}</span>
        <span class="k">else</span>
        <span class="o">{</span>
                        <span class="s2">&quot;Too low&quot;</span>
        <span class="o">}</span>
<span class="o">}</span>
</pre></div>
</div>
<img alt="../_images/zahlenraten.png" src="../_images/zahlenraten.png" />
</li>
<li><p class="first"><strong>Dateien kopieren</strong></p>
<blockquote>
<div><p>Diese Skripts sollen folgende Aufgaben ausführen:</p>
<ul class="simple">
<li>Durchsuchen des Ordners &#8220;C:Scripts&#8221; und dessen Unterordnern.</li>
<li>Durchsuchen jedes Ordners nach sämtlichen Textdateien (Dateien mit der Erweiterung .txt) und Prüfen des Erstellungsdatums jeder Datei.</li>
<li>Kopieren/Verschieben jeder .txt-Datei, die mehr als 10 Tage zuvor erstellt wurde, in den Ordner &#8220;C:Old&#8221;.</li>
<li>Ausgeben des Dateinamens (kein vollständiger Pfad, nur Dateiname) jeder kopierten Datei.</li>
<li>Ausgeben der Anzahl der kopierten Dateien.</li>
</ul>
<div class="highlight-sh"><div class="highlight"><pre>foreach <span class="o">(</span><span class="nv">$i</span> in Get-ChildItem C:<span class="se">\S</span>cripts -recurse<span class="o">)</span>
<span class="o">{</span>
        <span class="k">if</span> <span class="o">((</span><span class="nv">$i</span>.CreationTime -lt <span class="o">(</span><span class="k">$(</span>Get-Date<span class="k">)</span>.AddDays<span class="o">(</span>-10<span class="o">)))</span> -and <span class="o">(</span><span class="nv">$i</span>.Extension -eq <span class="s2">&quot;.txt&quot;</span><span class="o">))</span>
        <span class="o">{</span>
                <span class="c">#Copy-Item $i.FullName C:\old</span>
                <span class="nv">$i</span>.Name
                <span class="nv">$x</span> <span class="o">=</span> <span class="nv">$x</span> + 1
        <span class="o">}</span>
<span class="o">}</span>
<span class="s2">&quot;Total Files: &quot;</span> + <span class="nv">$x</span>
</pre></div>
</div>
</div></blockquote>
</li>
<li><p class="first"><strong>Fonts finden</strong></p>
</li>
</ul>
<div class="highlight-sh"><div class="highlight"><pre><span class="nv">$total</span> <span class="o">=</span> 0

<span class="nv">$a</span> <span class="o">=</span> get-item <span class="s2">&quot;hklm:\\Software\Microsoft\WindowsNT\CurrentVersion\Fonts&quot;</span>
<span class="nv">$f</span> <span class="o">=</span> <span class="nv">$a</span>.GetValueNames<span class="o">()</span>

foreach <span class="o">(</span><span class="nv">$i</span> in <span class="nv">$f</span><span class="o">)</span>
<span class="o">{</span>
        <span class="k">if</span> <span class="o">(</span><span class="nv">$i</span>.contains<span class="o">(</span><span class="s2">&quot;TrueType&quot;</span><span class="o">))</span>
        <span class="o">{</span>
                <span class="nv">$total</span>++
                <span class="nv">$i</span>
        <span class="o">}</span>
<span class="o">}</span>
</pre></div>
</div>
<ul>
<li><p class="first"><strong>Schleifen optimieren</strong></p>
<blockquote>
<div><p>Die Ausgabe des folgenden Powershell-Befehls dauert u.U. sehr lange. Verbessern Sie das Statement im Hinblick auf die Auführungsgeschwindigkeit</p>
<div class="highlight-sh"><div class="highlight"><pre><span class="c"># Foreach loop lists each element in a collection:</span>
Foreach <span class="o">(</span><span class="nv">$element</span> in Dir C:<span class="se">\ </span>-recurse<span class="o">)</span> <span class="o">{</span> <span class="nv">$element</span>.name <span class="o">}</span>
</pre></div>
</div>
<p>Lösung: Ersetze Foreach durch das ForEach-Objekt, das die Elemente der Pipeline sofort bearbeiten kann.</p>
<div class="highlight-sh"><div class="highlight"><pre><span class="c"># ForEach-Object lists each element in a pipeline:</span>
Dir C:<span class="se">\ </span>-recurse | ForEach-Object <span class="o">{</span> <span class="nv">$_</span>.name <span class="o">}</span>
</pre></div>
</div>
</div></blockquote>
</li>
<li><p class="first"><strong>Dateien per ftp hochladen</strong></p>
<blockquote>
<div><p>Sie sollen alle Dateien eines zu spezifizierenden Ordners auf einen ftp-server hochladen. Übergeben Sie den Ordner auf der Kommandozeile</p>
<div class="highlight-sh"><div class="highlight"><pre><span class="c">#we specify the directory where all files that we want to upload</span>
<span class="c">#$Dir=&quot;C:/Dir&quot;</span>

<span class="k">if</span><span class="o">(</span><span class="nb">test</span>-path <span class="nv">$args</span><span class="o">[</span>0<span class="o">])</span>
<span class="o">{</span>

        <span class="nv">$Dir</span><span class="o">=</span><span class="nv">$args</span><span class="o">[</span>0<span class="o">]</span>

        <span class="c">#ftp server</span>
        <span class="nv">$ftp</span> <span class="o">=</span> <span class="s2">&quot;ftp://ftp.server.com/dir/&quot;</span>
        <span class="nv">$user</span> <span class="o">=</span> <span class="s2">&quot;user&quot;</span>
        <span class="nv">$pass</span> <span class="o">=</span> <span class="s2">&quot;Pass&quot;</span>

        <span class="nv">$webclient</span> <span class="o">=</span> New-Object System.Net.WebClient

        <span class="nv">$webclient</span>.Credentials <span class="o">=</span> New-Object System.Net.NetworkCredential<span class="o">(</span><span class="nv">$user</span>,<span class="nv">$pass</span><span class="o">)</span>

        <span class="c">#list every sql server trace file</span>
        foreach<span class="o">(</span><span class="nv">$item</span> in <span class="o">(</span>dir <span class="nv">$Dir</span> <span class="s2">&quot;*.trc&quot;</span><span class="o">)){</span>
                <span class="s2">&quot;Uploading $item...&quot;</span>
                <span class="nv">$uri</span> <span class="o">=</span> New-Object System.Uri<span class="o">(</span><span class="nv">$ftp</span>+<span class="nv">$item</span>.Name<span class="o">)</span>
                <span class="nv">$webclient</span>.UploadFile<span class="o">(</span><span class="nv">$uri</span>, <span class="nv">$item</span>.FullName<span class="o">)</span>
         <span class="o">}</span>
<span class="o">}</span>
</pre></div>
</div>
<p>Unter-Windows kann man auch das BitsTransfer-Cmdlet benutzen.
Muss mit Import-Module BitsTransfer in die PS geladen werden (PS V. 2.0). Siehe dazu auch <a class="reference external" href="http://msdn.microsoft.com/en-us/library/ee663885%28v=VS.85%29.aspx">http://msdn.microsoft.com/en-us/library/ee663885%28v=VS.85%29.aspx</a></p>
</div></blockquote>
</li>
<li><p class="first"><strong>Übersicht über laufende Dienste</strong></p>
<blockquote>
<div><p>Verschaffen Sie sich einen Überblick über die laufenden Prozesse. Falls die Prozesse einen bestimmten Namen besitzen, stoppen Sie diese Prozesse bzw. geben das Wort &#8220;Gefunden &lt;Dienstname&gt; aus.</p>
<p>Erweitern Sie das Skript, indem Sie die laufenden Dienste in eine Datei schreiben, um sie später wie oben bereits geschehen, auszuwerten. Welche Schwierigkeiten können bei diesem Vorhaben auftreten.</p>
<div class="highlight-sh"><div class="highlight"><pre>Get-Service | ForEach-Object <span class="o">{</span>
        <span class="k">if</span><span class="o">(</span><span class="nv">$_</span>.ServiceName -match <span class="s2">&quot;RpcSs&quot;</span><span class="o">)</span>
        <span class="o">{</span>
                Stop-Service <span class="nv">$_</span>.ServiceName
                Write-Host <span class="s2">&quot;Gefunden: &quot;</span>  <span class="nv">$_</span>.Name
        <span class="o">}</span>
<span class="o">}</span>

Get-Service | Export-Clixml C:<span class="se">\d</span>ienste.xml
foreach <span class="o">(</span><span class="nv">$service</span> in Import-Clixml C:<span class="se">\d</span>ienste.xml<span class="o">)</span>
<span class="o">{</span>
        <span class="k">if</span><span class="o">(</span><span class="nv">$service</span>.ServiceName -match <span class="s2">&quot;RpcSs&quot;</span><span class="o">)</span>
        <span class="o">{</span>
                Write-Host <span class="s2">&quot;Gefunden: &quot;</span>  <span class="nv">$service</span>.Name
        <span class="o">}</span>
<span class="o">}</span>
</pre></div>
</div>
</div></blockquote>
</li>
<li><p class="first"><strong>Schätzen der Festplattenauslastung</strong></p>
<blockquote>
<div><p>Wie lange wird der Speicherplatz einer Festplatte ausreichen, wenn ihr Inhalt jeden Monat um ca. 7,5% wächst. Die Platte hat eine Kapazität von 2 TBiT, eine Startbelegung von 100 MBiT</p>
<div class="highlight-sh"><div class="highlight"><pre><span class="nv">$Zuwachs</span> <span class="o">=</span> 7.5
<span class="nv">$FestplatteMax</span> <span class="o">=</span> 2TB
<span class="nv">$StartKap</span> <span class="o">=</span> 100MB
<span class="nv">$FestplatteCurKap</span> <span class="o">=</span> <span class="nv">$StartKap</span>
<span class="nv">$i</span> <span class="o">=</span> 0
<span class="k">do</span>
<span class="o">{</span>

        <span class="nv">$FestplatteCurKap</span> *<span class="o">=</span> 1 + <span class="nv">$Zuwachs</span>/100
        <span class="nv">$i</span> +<span class="o">=</span> 1
        Write-Host <span class="s2">&quot;Monat: &quot;</span> <span class="nv">$i</span>

<span class="o">}</span><span class="k">while</span><span class="o">(</span><span class="nv">$FestplatteCurKap</span> -lt <span class="nv">$FestplatteMax</span><span class="o">)</span>

<span class="nv">$result</span> <span class="o">=</span> Get-Date
<span class="nv">$result</span> <span class="o">=</span> <span class="nv">$result</span>.AddMonths<span class="o">(</span><span class="nv">$i</span><span class="o">)</span>
<span class="nv">$result</span>
</pre></div>
</div>
</div></blockquote>
</li>
<li><p class="first"><strong>Berechnung des Notendurchnschnitts und Notenverteilung eines Testes</strong></p>
<blockquote>
<div><p>Ein Test ergab folgende Einzelnoten:
6,3,4,2,1,2,3,4,1,2,3,2,1,3,4,5,3,5,4,3,2,2,2,1,2,3</p>
<p>Berechnen Sie die Anzahl jeder Note sowie den Durchschnitt</p>
<p>Die folgende Lösung setzt in einigen Teilen die Pipeline der Powershell ein. Dies hätte auch durch eine weitere Schleife erledigt werden können.
Bei der Zuweisung der Häufigkeiten pro Noten wird ein 2. Array eingesetzt, ders ich pro Indexposition (ab 1) die absolute Zahl der jeweiligen Note merkt. In Indexposition 0 wird später der Durchschnitt abgelegt</p>
<div class="highlight-sh"><div class="highlight"><pre><span class="nv">$noten_sa1</span> <span class="o">=</span> 6,3,4,2,1,2,3,4,1,2,3,2,1,3,4,5,3,5,4,3,2,2,2,1,2,3
<span class="nv">$notenwerte</span> <span class="o">=</span> 1,2,3,4,5,6
<span class="nv">$notenstat</span> <span class="o">=</span> 0,0,0,0,0,0,0

1..6 | ForEach<span class="o">{</span>
        <span class="nv">$anzahl</span> <span class="o">=</span> 0
        <span class="k">for</span><span class="o">(</span><span class="nv">$i</span> <span class="o">=</span> 0;<span class="nv">$i</span> -lt <span class="nv">$noten_sa1</span>.length; <span class="nv">$i</span>++<span class="o">)</span>
        <span class="o">{</span>
                <span class="k">if</span><span class="o">(</span><span class="nv">$noten_sa1</span><span class="o">[</span><span class="nv">$i</span><span class="o">]</span> -eq <span class="nv">$_</span><span class="o">)</span>
                <span class="o">{</span>
                        Write-Host <span class="s2">&quot;Note &quot;</span>  <span class="nv">$_</span> <span class="s2">&quot;vorhanden an Position &quot;</span> + <span class="o">(</span><span class="nv">$i</span> + 1<span class="o">)</span>
                        <span class="nv">$anzahl</span>++
                <span class="o">}</span>
                <span class="k">else</span>
                <span class="o">{</span>
                        Write-Host <span class="s2">&quot;Note nicht vorhanden&quot;</span>
                <span class="o">}</span>
        <span class="o">}</span>
        <span class="nv">$notenstat</span><span class="o">[</span><span class="nv">$_</span><span class="o">]</span> <span class="o">=</span> <span class="nv">$anzahl</span>

<span class="o">}</span>
Write-Host <span class="nv">$notenstat</span>

<span class="nv">$durchschnitt</span> <span class="o">=</span> 0
<span class="nv">$quersumme</span><span class="o">=</span>0
<span class="k">for</span> <span class="o">(</span><span class="nv">$i</span> <span class="o">=</span> 1; <span class="nv">$i</span> -lt <span class="nv">$notenstat</span>.length;<span class="nv">$i</span>++<span class="o">)</span>
<span class="o">{</span>
        <span class="nv">$quersumme</span> +<span class="o">=</span> <span class="nv">$notenstat</span><span class="o">[</span><span class="nv">$i</span><span class="o">]</span>*<span class="nv">$i</span>
<span class="o">}</span>
<span class="nv">$durchschnitt</span> <span class="o">=</span> <span class="nv">$quersumme</span> / <span class="nv">$noten_sa1</span>.length
<span class="nv">$notenstat</span><span class="o">[</span>0<span class="o">]</span> <span class="o">=</span> <span class="nv">$durchschnitt</span>
<span class="nv">$quersumme</span>
<span class="nv">$durchschnitt</span>
</pre></div>
</div>
<p>Eine weitere und vielleicht elegantere Möglichkeit wäre die Verwendung einer Hashmap anstelle des Arrays $notenstat. Damit müsste man die Indexpositionen nicht <em>missbrauchen</em>, sondern könnte die Noten als Key und die Anzahl als Values einsetzen.</p>
<p>Eine Lösungsansatz:</p>
<div class="highlight-sh"><div class="highlight"><pre><span class="nv">$noten_sa1</span> <span class="o">=</span> 6,3,4,2,1,2,3,4,1,2,3,2,1,3,4,5,3,5,4,3,2,2,2,1,2,3
<span class="nv">$notenwerte</span> <span class="o">=</span> 1,2,3,4,5,6
<span class="nv">$notenhash</span> <span class="o">=</span> @<span class="o">{}</span>

1..6 | ForEach<span class="o">{</span>
        <span class="nv">$anzahl</span> <span class="o">=</span> 0
        <span class="k">for</span><span class="o">(</span><span class="nv">$i</span> <span class="o">=</span> 0;<span class="nv">$i</span> -lt <span class="nv">$noten_sa1</span>.length; <span class="nv">$i</span>++<span class="o">)</span>
        <span class="o">{</span>
                <span class="k">if</span><span class="o">(</span><span class="nv">$noten_sa1</span><span class="o">[</span><span class="nv">$i</span><span class="o">]</span> -eq <span class="nv">$_</span><span class="o">)</span>
                <span class="o">{</span>
                        <span class="c">#Write-Host &quot;Note &quot;  $_ &quot;vorhanden an Position &quot; + ($i + 1)</span>
                        <span class="nv">$anzahl</span>++
                <span class="o">}</span>
                <span class="k">else</span>
                <span class="o">{</span>
                        <span class="c"># Write-Host &quot;Note nicht vorhanden&quot;</span>
                <span class="o">}</span>
        <span class="o">}</span>
        <span class="nv">$notenhash</span>.Add<span class="o">(</span><span class="nv">$_</span>, <span class="nv">$anzahl</span><span class="o">)</span>
<span class="o">}</span>

<span class="nv">$durchschnitt</span> <span class="o">=</span> 0
<span class="nv">$quersumme</span> <span class="o">=</span> 0
foreach<span class="o">(</span><span class="nv">$key</span> in <span class="nv">$notenhash</span>.get_Keys<span class="o">())</span>
<span class="o">{</span>
        Write-Host <span class="nv">$key</span> <span class="nv">$notenhash</span><span class="o">[</span><span class="nv">$key</span><span class="o">]</span>
        <span class="nv">$quersumme</span> +<span class="o">=</span> <span class="nv">$key</span> * <span class="nv">$notenhash</span><span class="o">[</span><span class="nv">$key</span><span class="o">]</span>
<span class="o">}</span>
<span class="nv">$durchschnitt</span> <span class="o">=</span> <span class="nv">$quersumme</span> / <span class="nv">$noten_sa1</span>.length
<span class="nv">$durchschnitt</span>
</pre></div>
</div>
</div></blockquote>
</li>
</ul>
</div>


          </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="Allgemeiner Index"
             >Index</a></li>
        <li><a href="../index.html">PS4SYS</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2010, STE.
      Mit <a href="http://sphinx-doc.org/">Sphinx</a> 1.2b1 erstellt.
    </div>
  </body>
</html>